home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: For Experts: How to load a DLL dynamically ?
- Date: Sat, 16 Mar 1996 21:29:11 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4ifbpr$67s@news.halcyon.com>
- References: <4ibr0a$8f9@nms.telepost.no>
- NNTP-Posting-Host: blv-pm3-ip13.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Carsten Arnholm <ca@sesam.dnv.no> wrote:
-
- >Hi everyone,
-
- >I have a problem which I'm sure some of you experts can solve (???):
- >I'm using MSVC++ 4.0 under Windows NT 3.51.
-
- >I am unable to load a DLL exporting classes. If the DLL only exports
- >simple API functions, I can do:
-
- > // load the library
- > HINSTANCE myDLL = LoadLibrary("myDLL.dll");
- > const FARPROC myDLLfunc = GetProcAddress(myDLL ,"myDLLfunc");
- >
- > // call a function in the DLL that returns an int
- > int value = myDLLfunc();
- >
- > // DLL no longer needed
- > FreeLibrary(myDLL);
-
- >This is straightforward ...
-
-
- >But what do I do if I have a DLL which export classes ? i.e.
-
- >#ifdef DLL_IMPLEMENTATION
- > #define IMPORT_EXPORT _declspec(dllexport)
- >#else
- > #define IMPORT_EXPORT _declspec(dllimport)
- >#endif
-
- >class IMPORT_EXPORT DLLfoo { // class exported from dll
- >public:
- > DLLfoo(); // constructor
- > int bar(); // some member function
- >private:
- > int value;
- >};
-
- >In an application using the DLL, I want to:
-
- > DLLfoo foo; // create object from DLL class DLLfoo
- > int somevalue = foo.bar(); // call member function of that class
-
- >This is no problem if I link the application using the import library
- >of my DLL, but that means that the DLL is "started" together with the
- >application, whether I need it or not.
-
- >If I don't link with the import library, there are lots of unresolved
- >symbols (of course), and I can't figure out how to do something
- >similar to LoadLibrary/GetProcAddress for my classes and their members.
-
- >Any good Ideas ????
-
- >Would appreciate if you copied your reply to
- >my e-mail address: ca@sesam.dnv.no
-
-
- >Thanks,
- >Carsten Arnholm
-
- Um, I've never tried to GetProcAddress of a ctor in a late-bound DLL.
- Either early-bind the DLL (with an import-library) or GetProcAddress a
- 'C' function that instantiates the object for you and returns its
- pointer.
-
- --Norm
-
-
-
-
-
-